package com.cn.jinl.controller;

import com.cn.jinl.api.IViolationService;
import com.cn.jinl.domain.Violation;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created On : 2024/1/8.
 * <p>
 * Author : Huiyan
 * <p>
 * Description: 扩展应用---违章管理----控制层
 */
@Controller
@RequestMapping("/violation")
public class ViolationController {

    @Autowired
    private IViolationService violationService;


    /**
     * @author : Huiyan feng
     * @date   : 2024/1/8
     * @param  : [queryForm, frontToken]
     * @description : 获取待审批的所有罚单
     */
    @RequestMapping("/getPendingApprovalList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<Violation>> getPendingApprovalList(@RequestBody QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<Violation>> response = new JsonResponse<>();
        List<Violation> list = violationService.getPendingApprovalList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return response;
    }

    /**
     * @author : Huiyan feng
     * @date   : 2024/1/8
     * @param  : [queryForm, frontToken]
     * @description : 获取已审批的所有罚单
     */
    @RequestMapping("/getApprovedList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<Violation>> getApprovedList(@RequestBody QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<Violation>> response = new JsonResponse<>();
        List<Violation> list = violationService.getApprovedList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return response;
    }


    /**
     * @author : Huiyan feng
     * @date   : 2024/5/7
     * @param  : [queryForm, frontToken]
     * @description : 财务--扣减违章--违章明细  要求默认显示3个月内的已通过的罚单
     */
    @RequestMapping("/getApprovedRecentList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<Violation>> getApprovedRecentList(@RequestBody QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<Violation>> response = new JsonResponse<>();
        List<Violation> list = violationService.getApprovedRecentList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return response;
    }


    /**
     * @author : Huiyan feng
     * @date   : 2024/1/8
     * @param  : [violation, frontToken]
     * @description : 开罚单
     */
    @RequestMapping("/addViolation/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addViolation(@RequestBody Violation violation,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = violationService.addViolation(violation);
        return CommonUtil.getResponseData(response,result);
    }

    /**
     * @author : Huiyan feng
     * @date   : 2024/1/8
     * @param  : [violation, frontToken]
     * @description : 修改数据
     */
    @RequestMapping("/updateViolation/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateViolation(@RequestBody Violation violation,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = violationService.updateViolation(violation);
        return CommonUtil.getResponseData(response,result);
    }

    /**
     * @author : Huiyan feng
     * @date   : 2024/1/8
     * @param  : [queryForm, frontToken]
     * @return : com.cn.jinl.utils.JsonResponse<java.lang.String>
     * @description : 删除罚单
     */
    @RequestMapping("/deleteViolation/{frontToken}")
    @ResponseBody
    public JsonResponse<String> deleteViolation(@RequestBody QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = violationService.deleteViolation(queryForm);
        return CommonUtil.getResponseData(response,result);
    }


    /**
     * @author : Huiyan feng
     * @date   : 2024/1/9
     * @param  : [violation, frontToken]
     * @return : com.cn.jinl.utils.JsonResponse<java.lang.String>
     * @description : 更改数据状态    审批通过   数据作废  数据驳回
     */
    @RequestMapping("/updateFdStatus/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateFdStatus(@RequestBody Violation violation,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = violationService.updateFdStatus(violation);
        return CommonUtil.getResponseData(response,result);
    }






}
